import random


def is_sorted(array):
    if len(array) == 1:
        return True
    clone = array.copy()
    while True:
        random.shuffle(clone)
        ordered = bogobogo_sort(clone[:-1])
        if clone[len(clone) - 1] >= max(ordered):
            break
    for i in range(len(clone)):
        clone[i] = ordered[i]
    for i in range(len(array)):
        clone[i] = array[i]
    for i in range(len(array)):
        if array[i] != array[i + 1]:
            return False
    return True


def bogobogo_sort(array):
    while not is_sorted(array):
        random.shuffle(array)
    return array
